﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace KPIS.GERP.Models.HRM
{
    [Table("hrm_mp_job_sites"), DataContract]
    public class JobSite
    {
        public JobSite()
        {
            RecordStatus = "U";

            //LowerJobSites = new HashSet<JobSite>();
            //RefToJobSites = new HashSet<JobSite>();
            //AssetLocations = new HashSet<ICM.AssetLocation>();
            //MasExpenseRates = new HashSet<BGM.MasExpenseRate>();
            //RequestDtls = new HashSet<ICM.RequestParcelDtl>();
            //RequestParcels = new HashSet<ICM.RequestParcel>();
            //Dispenses = new HashSet<ICM.Dispense>();
        }

        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [DataMember, Display(Name = "JobSiteId", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("job_site_seq")]
        public int JobSiteId { get; set; }

        [DataMember, Display(Name = "Code", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("job_site_ref")]
        public string Code { get; set; }

        [DataMember, Display(Name = "Name", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("job_site_name")]
        public string Name { get; set; }

        [DataMember, Display(Name = "NameShort", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("job_site_name_short")]
        public string NameShort { get; set; }

        [DataMember, Display(Name = "NameEng", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("job_site_name_eng")]
        public string NameEng { get; set; }

        [DataMember, Display(Name = "NameEngShort", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("job_site_name_eng_short")]
        public string NameEngShort { get; set; }

        [DataMember, Display(Name = "GfmisCode", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("gfmis_code")]
        public string GfmisCode { get; set; }

        [ForeignKey("UpperJobSite")]
        [DataMember, Display(Name = "UpperJobSiteId", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("upper_job_site_seq")]
        public int? UpperJobSiteId { get; set; }

        [DataMember, Display(Name = "FullPath", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("job_site_full_path")]
        public string FullPath { get; set; }

        [DataMember, Display(Name = "RefJobSiteId", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("ref_job_site_seq")]
        public int? RefJobSiteId { get; set; }

        [ForeignKey("MasJobSiteType")]
        [DataMember, Display(Name = "JobSiteTypeId", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("job_site_type_seq")]
        public int? JobSiteTypeId { get; set; }

        [ForeignKey("MasWorkArea")]
        [DataMember, Display(Name = "WorkAreaId", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("work_area_seq")]
        public int? WorkAreaId { get; set; }

        [ForeignKey("MasJobSiteLevel")]
        [DataMember, Display(Name = "JobSiteLevelId", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("job_site_level_seq")]
        public int? JobSiteLevelId { get; set; }

        //[ForeignKey("HeaderPosition")] //{"One or more validation errors were detected during model 
        // generation:\r\n\r\n\\tSystem.Data.Entity.Edm.EdmAssociationEnd: : Multiplicity is not valid in Role 
        //'Position_JobSite_Target' in relationship 'Position_JobSite'. Because the Dependent Role 
        //properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.\r\n"}
        //มีปัญหาในการทำ ForeignKey
        [DataMember, Display(Name = "HeaderPosId", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("head_pos_seq")]
        public int? HeaderPosId { get; set; }

        [DataMember, Display(Name = "Address", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("address")]
        public string Address { get; set; }

        [DataMember]
        [Column("address2")]
        public string Address2 { get; set; }

        [ForeignKey("MasDistrict")]
        [DataMember, Display(Name = "DistrictId", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("district_seq")]
        public int? DistrictId { get; set; }

        [ForeignKey("MasProvince")]
        [DataMember, Display(Name = "ProvnceId", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("provnce_seq")]
        public int? ProvnceId { get; set; }

        [ForeignKey("MasCity")]
        [DataMember, Display(Name = "CityId", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("city_seq")]
        public int? CityId { get; set; }

        [ForeignKey("MasCountry")]
        [DataMember, Display(Name = "CountryId", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("country_seq")]
        public int? CountryId { get; set; }

        [DataType(DataType.PostalCode, ErrorMessageResourceType = typeof(Resources.JobSiteResource), ErrorMessageResourceName = "PostalCodeError")]
        [DataMember, Display(Name = "PostalCode", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("postal_code")]
        public string PostalCode { get; set; }

        [DataType(DataType.PhoneNumber, ErrorMessageResourceType = typeof(Resources.JobSiteResource), ErrorMessageResourceName = "TelError")]
        [DataMember, Display(Name = "Tel", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("tel")]
        public string Tel { get; set; }

        [DataType(DataType.PhoneNumber, ErrorMessageResourceType = typeof(Resources.JobSiteResource), ErrorMessageResourceName = "FaxError")]
        [DataMember, Display(Name = "Fax", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("fax")]
        public string Fax { get; set; }

        [DataType(DataType.Url, ErrorMessageResourceType = typeof(Resources.JobSiteResource), ErrorMessageResourceName = "WebAddressError")]
        [DataMember, Display(Name = "WebAddress", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("webaddress")]
        public string WebAddress { get; set; }

        [ForeignKey("MasJobSiteStatus")]
        [DataMember, Display(Name = "JobSiteStatusId", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("job_site_status_seq")]
        public int? JobSiteStatusId { get; set; }

        [DataType(DataType.MultilineText)]
        [DataMember, Display(Name = "JobDescription", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("job_description")]
        public string JobDescription { get; set; }

        [DataType(DataType.MultilineText)]
        [DataMember, Display(Name = "Remarks", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("remarks")]
        public string Remarks { get; set; }

        [EnumDataType(typeof(SYS.RecordStatus.EnumRecordStatus))]
        [DataMember, Display(Name = "RecordStatus", ResourceType = typeof(Resources.JobSiteResource))]
        [Column("record_status")]
        public string RecordStatus { get; set; }

        [Column("created_by")]
        public int? CreatedBy { get; set; }
        [Column("created_when")]
        public DateTime? CreatedWhen { get; set; }
        [Column("updated_by")]
        public int? UpdatedBy { get; set; }
        [Column("updated_when")]
        public DateTime? UpdatedWhen { get; set; }


        [DataMember]
        public virtual JobSite UpperJobSite { get; set; }

        //[DataMember]
       // public virtual JobSite RefJobSite { get; set; }

        [DataMember]
        public virtual MasJobSiteType MasJobSiteType { get; set; }

        //[DataMember]
        //public virtual ExecutivePosition ExecutivePosition { get; set; }

        //[DataMember]
        //public virtual MasEmployeeType MasEmployeeType { get; set; }

        [DataMember]
        public virtual MasWorkArea MasWorkArea { get; set; }

        [DataMember]
        public virtual MasJobSiteLevel MasJobSiteLevel { get; set; }

        //[DataMember]
        //public virtual Position HeaderPosition { get; set; }

        [DataMember]
        public virtual MasDistrict MasDistrict { get; set; }

        [DataMember]
        public virtual MasProvince MasProvince { get; set; }

        [DataMember]
        public virtual MasCity MasCity { get; set; }

        [DataMember]
        public virtual MasCountry MasCountry { get; set; }

        [DataMember]
        public virtual MasJobSiteStatus MasJobSiteStatus { get; set; }


        [DataMember, InverseProperty("CurrentJobSite")]
        public virtual ICollection<MasJobSiteType> MasJobSiteTypes { get; set; }

        //[DataMember, InverseProperty("UpperJobSite")]
        //public virtual ICollection<JobSite> LowerJobSites { get; set; }


        //[DataMember]
        //public virtual ICollection<ICM.AssetLocation> AssetLocations { get; set; }

        //[DataMember]
        //public virtual ICollection<BGM.MasExpenseRate> MasExpenseRates { get; set; }

        //[DataMember]
        //public virtual ICollection<ICM.RequestParcelDtl> RequestDtls { get; set; }

        //[DataMember]
        //public virtual ICollection<ICM.RequestParcel> RequestParcels { get; set; }

        //[DataMember]
        //public virtual ICollection<ICM.Dispense> Dispenses { get; set; }

    }
}
